package org.cn.hj.org.contoller;

import com.github.pagehelper.PageInfo;
import org.cn.hj.basic.common.ResultJson;
import org.cn.hj.org.dto.DepartmentDto;
import org.cn.hj.org.service.IDepartmentService;
import org.cn.hj.org.vo.DepartmentVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Department")
public class DepartmentController {

    @Resource
    private IDepartmentService departmentService;

    /**
     * 通过id删除数据
     * @param id
     */
    @GetMapping("remove/{id}")
    public ResultJson remove(@PathVariable Long id){
        departmentService.remove(id);
        return ResultJson.success();
    };

    /**
     * 新增数据
     * @param departmentDto
     */
    @PostMapping("/add")
    public ResultJson add(@RequestBody DepartmentDto departmentDto){
        departmentService.add(departmentDto);
        return ResultJson.success();
    };

    /**
     * 修改数据
     * @param departmentDto
     */
    @PostMapping("/update")
    public ResultJson  update(@RequestBody DepartmentDto departmentDto){
        departmentService.update(departmentDto);
        return ResultJson.success();
    };

    /**
     * 查询分页数据
     * @param departmentDto
     * @return
     */
    @PostMapping("/getPageList")
    public ResultJson  getPageList(@RequestBody DepartmentDto departmentDto){
        PageInfo<DepartmentVo> pageList = departmentService.getPageList(departmentDto);
        return ResultJson.success(pageList);
    };


    /**
     * 根据id获取一条数据
     * @param id
     * @return
     */
    @GetMapping("find/{id}")
    public ResultJson  findOneById(@PathVariable Long id){
        DepartmentVo oneById = departmentService.findOneById(id);
        return ResultJson.success(oneById);
    };

}
